﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>商品编号增加器</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        .v-enter, .v-leave-to {
            opacity: 0;
        }
        .v-enter-active, .v-leave-active {
            transition: opacity 2s;
        }
    </style>
</head>

<body>
    <div id="app">
        <transition-group>
            <!-- 这里尽量不使用index作为key -->
            <div v-for="(item, index) in list" :key="item.id">
                {{ item.title }}
            </div>
        </transition-group>
        <button @click="handleBtnClick">增加</button>
    </div>
    <script>
        var count = 0;
        const vm = Vue.createApp({
            data() {
                return {
                    list: []
                }
            },
            methods: {
                handleBtnClick() {
                    this.list.push({
                        id:count++,
                        title: `商品编号： ${count}`
                    })
                }
            }

        }).mount('#app');
    </script>
</body>

</html>